# # 三目运算符
# print("Yes" if True else "No")
# print("Yes" if False else "No")

# # 匿名函数
# def add(n1, n2):
#     return n1 + n2
# result = add(1, 2)
# print(result)
#
# add = lambda x,y: x*y
# result = add(2,3)
# print(result)
#
# func = lambda x: x**2 if x > 3 else x**3
# print(func(3))

# # 元组推导式
# # 生成100以内能被7整除所有数字的元组
# t3 = (x for x in range(100) if x%7==0)
#
# # 列表推导式
# # 生成100以内能被7整除所有数字的元组
# l3 = [x for x in range(100) if x%7==0]

# # 字典推导式
# names = ['Bob','Tom','alice','Jerry','Wendy','Smith']
# # 将列表中各字符串值为键，各字符串的长度为值，组成键值对
# new_dict = {name:len(name) for name in names}
# print(new_dict)

# # 集合推导式
# data = ['Bob','123','Tom','Jerry']
# # 筛选列表中的数字字符串
# new_set = {n for n in data if n.isdigit()}
# print(new_set)

# 文件操作
# 以写入文件打开 index.txt 文件
# file = open("index.txt", "w")  # r:只读方式   a:追加写入方式
# 向文件中写入指定字符串
# file.write("AAAA")

# file1 = open("data.html","w")
# length= file1.write("<h1>This is a new Page</h1>")
# print(f"成功写入{length}个字节")
# file1.close()

# # 向文件中写入一序列的字符串
# data = ["AAAAAAAAAAAA\n","BBBBBBBBBBBB\n","CCCCCCCCCCCC\n"]
# file = open('data.txt',"w")
# file.writelines(data)
# file.close()

# # 从文件读取指定的字节数
# file = open('data.txt', "r")
# # 读取10个字符
# content = file.read(10)
# print(content, end="")  # 不换行
# # 读取所有内容
# content = file.read()
# print(content)
# file.close()

# 从文件读取整行，包括 \n 字符
# content = file.readline(10)
# print(content)
# 读取一行所有内容
# content = file.readline()
# print(content)
# file.close()

# 读取所有行(直到结束符 EOF)并返回列表
# content = file.readlines()
# print(content)
# file.close()

# 上下文管理器 with 默认有关闭文件操作
with open("data.txt", "r") as file:
    content = file.read()
    print(content)